﻿Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Search

Namespace Components
    Public Class AccordionTabController
        Inherits PortalModuleBase

        Public Function GetTabs(ByVal ModuleID As Integer) As AccordionTabs
            Try
                Dim AccordionTabData As New Data.SqlDataProvider
                Dim CurrentTabs As New AccordionTabs
                '
                'Retrieve the Tabs for this module instance.
                '
                Dim RetrievedTabs As IDataReader = AccordionTabData.GetTabs(ModuleID)
                '
                'Convert the datarows into AccordionTab objects
                '
                While RetrievedTabs.Read
                    Dim CurrentTab As New AccordionTab
                    CurrentTab.ModuleID = CType(RetrievedTabs.GetValue(0), Integer)
                    CurrentTab.ItemID = CType(RetrievedTabs.GetValue(1), Integer)
                    CurrentTab.TitleOfTab = CType(RetrievedTabs.GetValue(2), String)
                    CurrentTab.ContentOfTab = CType(RetrievedTabs.GetValue(3), String)
                    CurrentTab.IsVisible = CType(RetrievedTabs.GetValue(4), Boolean)
                    If Not IsDBNull(RetrievedTabs.GetValue(5)) Then
                        CurrentTab.SortOrder = CType(RetrievedTabs.GetValue(5), Integer)
                    Else
                        CurrentTab.SortOrder = 0
                    End If
                    '
                    'Add our retrieved Tab into the current collection of Tabs we have.
                    '
                    CurrentTabs.Add(CurrentTab)
                End While
                '
                'We retrieved our Tabs, return the collection of Tabs to the calling code.
                '
                Return CurrentTabs
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
                Return Nothing
            End Try
        End Function

        Public Function GetTabsReverse(ByVal ModuleID As Integer) As AccordionTabs
            Try
                Dim AccordionTabData As New Data.SqlDataProvider
                Dim CurrentTabs As New AccordionTabs
                '
                'Retrieve the Tabs for this module instance.
                '
                Dim RetrievedTabs As IDataReader = AccordionTabData.GetTabs(ModuleID)
                '
                'Convert the datarows into AccordionTab objects
                '
                While RetrievedTabs.Read
                    Dim CurrentTab As New AccordionTab
                    CurrentTab.ModuleID = CType(RetrievedTabs.GetValue(0), Integer)
                    CurrentTab.ItemID = CType(RetrievedTabs.GetValue(1), Integer)
                    CurrentTab.TitleOfTab = CType(RetrievedTabs.GetValue(2), String)
                    CurrentTab.ContentOfTab = CType(RetrievedTabs.GetValue(3), String)
                    CurrentTab.IsVisible = CType(RetrievedTabs.GetValue(4), Boolean)
                    If Not IsDBNull(RetrievedTabs.GetValue(5)) Then
                        CurrentTab.SortOrder = CType(RetrievedTabs.GetValue(5), Integer)
                    Else
                        CurrentTab.SortOrder = 0
                    End If
                    '
                    'Add our retrieved Tab into the current collection of Tabs we have.
                    '
                    CurrentTabs.Add(CurrentTab)
                End While
                '
                'We retrieved our Tabs, return the collection of Tabs to the calling code.
                '
                Return CurrentTabs
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
                Return Nothing
            End Try
        End Function

        Public Function GetTab(ByVal ModuleID As Integer, ByVal ItemID As Integer) As AccordionTab
            Try
                Dim AccordionTabData As New Data.SqlDataProvider
                Dim CurrentTab As New AccordionTab
                '
                'Retrieve the requested Tab for this current instance.
                '
                Dim RetrievedTab As IDataReader = AccordionTabData.GetSingleTab(ModuleID, ItemID)
                '
                'Convert the datarow into a AccordionTab object.
                '
                If RetrievedTab.Read = True Then
                    CurrentTab.ModuleID = CType(RetrievedTab.GetValue(0), Integer)
                    CurrentTab.ItemID = CType(RetrievedTab.GetValue(1), Integer)
                    CurrentTab.TitleOfTab = CType(RetrievedTab.GetValue(2), String)
                    CurrentTab.ContentOfTab = CType(RetrievedTab.GetValue(3), String)
                    CurrentTab.IsVisible = CType(RetrievedTab.GetValue(4), Boolean)
                    If Not IsDBNull(RetrievedTab.GetValue(5)) Then
                        CurrentTab.SortOrder = CType(RetrievedTab.GetValue(5), Integer)
                    Else
                        CurrentTab.SortOrder = 0
                    End If
                    '
                    'The Tab has been retrieved, return it to the calling code.
                    '
                    Return CurrentTab
                Else
                    '
                    'No Tab found with that ItemID, return nothing.
                    '
                    Return Nothing
                End If
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
                Return Nothing
            End Try
        End Function

        Public Sub DeleteTab(ByVal ModuleID As Integer, ByVal ItemID As Integer)
            Try
                Dim AccordionTabDataController As New Data.SqlDataProvider
                '
                'Simple call to delete the Tab.
                '
                AccordionTabDataController.DeleteTab(ModuleID, ItemID)
                '
                'And we are done.
                '
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub DeleteAllTabs(ByVal ModuleID As Integer)
            Try
                Dim AccordionTabDataController As New Data.SqlDataProvider
                '
                'Simple call to delete all of the Tabs.
                '
                AccordionTabDataController.DeleteAllTabs(ModuleID)
                '
                'We are done.
                '
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub InsertTab(ByVal TabToInsert As AccordionTab)
            Try
                Dim AccordionTabDataController As New Data.SqlDataProvider
                AccordionTabDataController.InsertTab(TabToInsert.ModuleID, TabToInsert.TitleOfTab, TabToInsert.ContentOfTab, TabToInsert.IsVisible, TabToInsert.SortOrder)
                '
                'Tab has been inserted. Give control back to the calling code.
                '
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub ModifyTab(ByVal TabToModify As AccordionTab)
            Try
                Dim AccordionTabDataController As New Data.SqlDataProvider
                AccordionTabDataController.ModifyTab(TabToModify.ModuleID, TabToModify.ItemID, TabToModify.TitleOfTab, TabToModify.ContentOfTab, TabToModify.IsVisible, TabToModify.SortOrder)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub ModifyTabSortOrder(ByVal TabToModify As AccordionTab)
            Try
                Dim AccordionTabDataController As New Data.SqlDataProvider
                AccordionTabDataController.ModifyTabSortOrder(TabToModify.ModuleID, TabToModify.ItemID, TabToModify.SortOrder)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Function GetDisplayStyles(ByVal ModuleID As Integer) As DisplayStyles
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider
                Dim CurrentStyles As New DisplayStyles

                Dim RetrievedStyles As IDataReader = DisplayStyleData.GetDisplayStyles(ModuleID)

                While RetrievedStyles.Read
                    Dim CurrentStyle As New DisplayStyle
                    CurrentStyle.ModuleID = CType(RetrievedStyles.GetValue(0), Integer)
                    CurrentStyle.DisplayStyleID = CType(RetrievedStyles.GetValue(1), Integer)
                    CurrentStyle.DisplayStyle = CType(RetrievedStyles.GetValue(2), String)
                    If Not IsDBNull(RetrievedStyles.GetValue(3)) Then
                        CurrentStyle.DisplayStyleNotes = CType(RetrievedStyles.GetValue(3), String)
                    Else
                        CurrentStyle.DisplayStyleNotes = ""
                    End If
                    CurrentStyles.Add(CurrentStyle)
                End While

                Return CurrentStyles
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
                Return Nothing
            End Try
        End Function

        Public Function GetDisplayStyle(ByVal ModuleID As Integer, ByVal DisplayStyleID As Integer)
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider
                Dim CurrentStyle As New DisplayStyle

                Dim RetrievedStyle As IDataReader = DisplayStyleData.GetDisplayStyle(ModuleID, DisplayStyleID)

                If RetrievedStyle.Read = True Then
                    CurrentStyle.ModuleID = CType(RetrievedStyle.GetValue(0), Integer)
                    CurrentStyle.DisplayStyleID = CType(RetrievedStyle.GetValue(1), Integer)
                    CurrentStyle.DisplayStyle = CType(RetrievedStyle.GetValue(2), String)
                    If Not IsDBNull(RetrievedStyle.GetValue(3)) Then
                        CurrentStyle.DisplayStyleNotes = CType(RetrievedStyle.GetValue(3), String)
                    Else
                        CurrentStyle.DisplayStyleNotes = ""
                    End If
                    Return CurrentStyle
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
                Return Nothing
            End Try
        End Function

        Public Sub InsertDisplayStyle(ByVal DisplayStyleToInsert As DisplayStyle)
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider

                DisplayStyleData.AddDisplayStyle(DisplayStyleToInsert.ModuleID, DisplayStyleToInsert.DisplayStyle, DisplayStyleToInsert.DisplayStyleNotes)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub UpdateDisplayStyle(ByVal DisplayStyleToUpdate As DisplayStyle)
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider

                DisplayStyleData.ModifyDisplayStyle(DisplayStyleToUpdate.ModuleID, DisplayStyleToUpdate.DisplayStyleID, _
                                                    DisplayStyleToUpdate.DisplayStyle, DisplayStyleToUpdate.DisplayStyleNotes)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub DeleteDisplayStyle(ByVal DisplayStyleToDelete As DisplayStyle)
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider

                DisplayStyleData.DeleteDisplayStyle(DisplayStyleToDelete.ModuleID, DisplayStyleToDelete.DisplayStyleID)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub

        Public Sub DeleteAllDisplayStyles(ByVal ModuleID As Integer)
            Try
                Dim DisplayStyleData As New Data.SqlDataProvider

                DisplayStyleData.DeleteAllDisplayStyles(ModuleID)
            Catch ex As Exception
                '
                'TODO: Error Handling
                '
            End Try
        End Sub
    End Class
End Namespace

